const oss = require('ali-oss');
const config = require('../config');
const client = oss({
	secure:true,
	region: config.oss.region,
	accessKeyId: config.oss.accessKeyId,
	accessKeySecret: config.oss.accessKeySecret,
	bucket: config.oss.bucket,
});
import {createOssPath} from '@/utils'

export function uploadFile (localFile,folder='') {
	return new Promise((resolve,reject)=>{
		var ossObj=createOssPath(localFile,folder)
		client.put(ossObj.fileName, ossObj.file).then(res=>{
			resolve(config.oss.url+res.name)
		}).catch(err=>{
			reject(err)
		})
	})
}
